import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:package_info_plus/package_info_plus.dart';

class Device {
  static Device? _instance;
  static String? _packageName;
  static String? _version;
  static String? _buildNumber;

  Device._();

  factory Device() {
    return _instance!;
  }

  static Future<bool> init() async {
    _instance ??= Device._();
    try {
      PackageInfo packageInfo = await PackageInfo.fromPlatform();
      _packageName = packageInfo.packageName;
      _version = packageInfo.version;
      _buildNumber = packageInfo.buildNumber;
    } catch (e) {
      print(e);
      return false;
    }
    return true;
  }

  static bool get isDesktop => !isWeb && (isWindows || isLinux || isMacOS);

  static bool get isMobile => isAndroid || isIOS;

  static bool get isWeb => kIsWeb;

  static bool get isWindows => Platform.isWindows;

  static bool get isLinux => Platform.isLinux;

  static bool get isMacOS => Platform.isMacOS;

  static bool get isAndroid => Platform.isAndroid;

  static bool get isFuchsia => Platform.isFuchsia;

  static bool get isIOS => Platform.isIOS;

  static String get packageName => _packageName!;

  static String get version => _version!;

  static String get buildNumber => _buildNumber!;
}
